﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr XMLNS:MSHelp = "http://msdn.microsoft.com/mshelp" xmlns:ddue = 
"http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink = 
"http://www.w3.org/1999/xlink" xmlns:tool = "http://www.microsoft.com/tooltip" 
XMLNS:[default] http://ddue.schemas.microsoft.com/authoring/2003/5 = 
"http://ddue.schemas.microsoft.com/authoring/2003/5"><HEAD><TITLE>WebHttp Sample</TITLE>
<META content="text/html; CHARSET=utf-8" http-equiv=Content-Type></META>
<META name=save content=history></META><LINK rel=stylesheet type=text/css 
href="../../../../CommonFiles/Classic.css"></LINK>

<META name=GENERATOR content="MSHTML 8.00.6001.18783"></HEAD>
<BODY><INPUT id=userDataCache class=userDataStyle type=hidden></INPUT><INPUT 
id=hiddenScrollOffset type=hidden></INPUT><IMG 
style="WIDTH: 0px; DISPLAY: none; HEIGHT: 0px" id=dropDownImage 
src="../../../../../Common/Html/drpdown.gif"></IMG><IMG 
style="WIDTH: 0px; DISPLAY: none; HEIGHT: 0px" id=dropDownHoverImage 
src="../../../../../Common/Html/drpdown_orange.gif"></IMG><IMG 
style="WIDTH: 0px; DISPLAY: none; HEIGHT: 0px" id=copyImage 
src="../../../../../Common/Html/copycode.gif"></IMG><IMG 
style="WIDTH: 0px; DISPLAY: none; HEIGHT: 0px" id=copyHoverImage 
src="../../../../../Common/Html/copycodeHighlight.gif"></IMG>
<DIV id=header>
<TABLE id=topTable width="100%">
  <TBODY>
  <TR id=headerTableRow1>
    <TD align=left><SPAN id=runningHeaderText></SPAN></TD></TR>
  <TR id=headerTableRow2>
    <TD align=left><SPAN id=nsrTitle>WebHttp Sample</SPAN></TD></TR>
  <TR id=headerTableRow3>
    <TD></TD></TR></TBODY></TABLE>
</DIV>
<DIV id=mainSection>
<DIV id=mainBody>
<DIV id=allHistory class=saveHistory onload="loadAll()" 
onsave="saveAll()"></DIV>
<P>This sample demonstrates how to use the <B>WebHttpRelayBinding</B> binding to 
return binary data using the Web programming model.</P>
<H2 class=heading>Prerequisites</H2>
<DIV id=sectionSection0 class=section><content 
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
<P xmlns="">If you haven't already done so, please read the release notes document that 
explains how to sign up for a Windows Azure account and how 
to configure your environment.</P></content></DIV>
<H2 class=heading>Service</H2>
<DIV id=sectionSection1 class=section><content 
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
<P xmlns="">The service project defines a simple contract. The 
<CODE>OperationContractAttribute</CODE> and <CODE>WebGetAttribute</CODE> attributes are applied 
    to the <CODE>GetImage</CODE> method.</P>
<DIV class=code xmlns=""><SPAN codeLanguage="CSharp">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
  <TBODY>
  <TR>
    <TH>C#&nbsp;</TH>
</TR>
  <TR>
    <TD colSpan=2><PRE>[ServiceContract(Name = "ImageContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
public interface IImageContract
{
    [OperationContract, WebGet]
    Stream GetImage();
}</PRE>
      </TD></TR></TBODY></TABLE></SPAN></DIV>
<P xmlns="">The ImageContract</CODE> contract is implemented by the 
<CODE>ImageService</CODE> class. This class reads a bitmap from a file (included 
in the solution). When <CODE>GetImage</CODE> is called, the response returns a 
message that contains the image. The configuration uses the 
<CODE>WebHttpRelayBinding</CODE> binding. Note that <CODE>relayClientAuthenticationType</CODE> is set to <strong>None</strong>, 
therefore the client credential is not required when sending an HTTP GET request.</P>
<DIV class=code xmlns=""><SPAN codeLanguage="xml">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
  <TBODY>
  <TR>
    <TH>Xml&nbsp;</TH>
</TR>
  <TR>
    <TD colSpan=2><PRE>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;system.serviceModel&gt;
    &lt;bindings&gt;
      &lt;!-- Application Binding --&gt;
      &lt;webHttpRelayBinding&gt;
        &lt;binding name="default"&gt;
            &lt;security relayClientAuthenticationType=&quot;None&quot; /&gt;
        &lt;/binding&gt;
      &lt;/webHttpRelayBinding&gt;
    &lt;/bindings&gt;

    &lt;services&gt;
      &lt;!-- Application Service --&gt;
      &lt;service name="Microsoft.ServiceBus.Samples.ImageService"
               behaviorConfiguration="default"&gt;
        &lt;endpoint name="RelayEndpoint"
                  contract="Microsoft.ServiceBus.Samples.IImageContract"
                  binding="webHttpRelayBinding"
                  bindingConfiguration="default"
                  behaviorConfiguration="sharedSecretClientCredentials"
                  address="" /&gt;
      &lt;/service&gt;
    &lt;/services&gt;

    &lt;behaviors&gt;
      &lt;endpointBehaviors&gt;
        &lt;behavior name="sharedSecretClientCredentials"&gt;
          &lt;transportClientEndpointBehavior credentialType=&quot;SharedSecret"&gt;
             &lt;clientCredentials&gt;
               &lt;sharedSecret issuerName=&quot;ISSUER_NAME&quot; issuerSecret=&quot;ISSUER_SECRET&quot;/&gt;
             &lt;/clientCredentials&gt;
          &lt;/transportClientEndpointBehavior&gt;
        &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;
      &lt;serviceBehaviors&gt;
        &lt;behavior name="default"&gt;
          &lt;serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" /&gt;
        &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
&lt;/configuration&gt;</PRE>
      </TD></TR></TBODY></TABLE></SPAN></DIV></content></DIV>
      
<H2 class=heading>Client</H2><DIV id=sectionSection2 class=section
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
<P xmlns="">For this sample, the client can be any web browser. The browser can send an HTTP GET 
    to the service, and the request is mapped to a
    <strong>GetImage</strong> operation.</P> 
</content></DIV>
<H2 class=heading>Building and Running the Sample</H2>
<DIV id=sectionSection3 class=section><content 
xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
<P xmlns="">Before building the solution, do the following to update the
    App.config file:</P>
<OL class=ordered xmlns="">
  <LI>Open the App.config file under the \Service project. Replace ISSUER_NAME 
      with the actual issuer name and ISSUER_SECRET with the actual issuer secret.
  </LI><BR></OL>
<P xmlns="">After building the solution, perform the following steps to obtain the 
    image:</P>
<OL class=ordered xmlns="">
  <LI>From a command prompt, run the service 
  (Service\bin\Debug\Service.exe).<BR><BR>
  <LI>When prompted, enter the service namespace name.<BR><BR>
  <LI>At this point, the service should indicate that it is listening at the 
  configured address. <BR><BR>
  <LI>Navigate to the URL provided by the service using any Web browser, and view the 
      returned image.<BR>
      <BR></OL>
      
      </content></DIV><!--[if gte IE 5]><tool:tip 
avoidmouse="false" element="languageFilterToolTip"></tool:tip><![endif]--></DIV>
<P xmlns="">
    <hr /> 
    Did you find this information useful?&nbsp; <a href="http://go.microsoft.com/fwlink/?LinkID=155664">Please send your suggestions and comments about the documentation.</a>
    
    </P></DIV></BODY></HTML>
